﻿package nieflash.html {
	import flash.net.navigateToURL;
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	
	public class navigate {
		private static var bType:String = "none";
		private static var randomNun:int = 0;
		
		public static function linkReady(_url:String = "", _target:String = ""):Boolean {
			if (bType == "none") {
				randomNun = Math.random() * 100;
				var randomString:String = "ieHref" + String(randomNun);
				bType = js.getBrowserType();
				if (bType.indexOf("msie") != -1) {
					if (_url == "" && _target == "") {
						navigateToURL(new URLRequest("javascript:(function(){var _a=document.createElement('a');_a.id='" + randomString + "';document.body.appendChild(_a);})();function getAndClick" + randomString + "(href,target){var _a=document.getElementById('" + randomString + "');_a.href=href;_a.target=target;_a.click();};"), "_self");
					}else {
						navigateToURL(new URLRequest("javascript:(function(){var _a=document.createElement('a');_a.id='" + randomString + "';document.body.appendChild(_a);})();function getAndClick" + randomString + "(href,target){var _a=document.getElementById('" + randomString + "');_a.href=href;_a.target=target;_a.click();};getAndClick" + randomString + "('" + _url + "','" + _target + "')"), "_self");
						return true;
					}
				}
			}
			return false;
		}
		
		public static function getURL(_url:String, _target:String = "_blank") {
			if (linkReady(_url, _target)) {
				return;
			}
			
			if (bType.indexOf("msie") != -1) {
				ExternalInterface.call("getAndClick" + "ieHref" + String(randomNun), _url, _target);
				//navigateToURL(new URLRequest("javascript:(function(){var _a=document.createElement('a');_a.id='1';document.body.appendChild(_a);})();function getAndClick1(href,target){var _a=document.getElementById('1');_a.href=href;_a.target=target;_a.click();};getAndClick1('" + _url + "','_blank');"), _target);
			}else {
				navigateToURL(new URLRequest(_url), _target);
			}
		}
	}
}